home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / FINDSTR.ICN < prev    next >
Text File  |  1992-11-26  |  2KB  |  75 lines

  1. ############################################################################
  2. #
  3. #    File:     findstr.icn
  4. #
  5. #    Subject:  Program to find imbedded character strings
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     September 11, 1990
  10. #
  11. ###########################################################################
  12. #
  13. #  Utility filter to list character strings imbedded in data files (e.g.
  14. #  object files).
  15. #
  16. #    findstr -options file...
  17. #
  18. #    -l length    minimum string size to be printed (default 3)
  19. #    -c chars    a string of characters (besides the standard ASCII
  20. #            printable characters) to be considered part of a
  21. #            string
  22. #
  23. #  Icon string escape sequences can be used to specify the -c option.
  24. #
  25. #  Multiple files can be specified as arguments, and will be processed
  26. #  in sequence.
  27. #
  28.  
  29. link options,escape
  30.  
  31. procedure main(arg)
  32.    local c, f, fn, header, min_string_size, okchars, opt, s, istring
  33.    #
  34.    #  Process command line options and file names.
  35.    #
  36.    opt := options(arg,"l+c:")
  37.    if *arg = 0 then stop("Usage: findstr -options file..._
  38.       \n_
  39.       \n-l length\tminimum string size to be printed (default 3)_
  40.       \n-c chars\ta string of characters (besides the standard ASCII_
  41.       \n\t\tprintable characters) to be considered part of a string_
  42.       \n")
  43.    #
  44.    #  Define minimum string size to print.
  45.    #
  46.    min_string_size := \opt["l"] | 3    # default min string size = 3
  47.    #
  48.    #  Define characters that can be in strings.
  49.    #
  50.    okchars := cset(&ascii[33:-1])    # normal ASCII printable characters
  51.    okchars ++:= istring(\opt["c"])    # additional chars supplied by user
  52.    #
  53.    #  Loop to process files.
  54.    #
  55.    every fn := !arg do {
  56.       f := open(fn,"u") | stop("Can't open input file \"",fn,"\"")
  57.       #
  58.       #  Now find and print the strings.
  59.       #
  60.       header := if *arg > 1 then fn || ": " else ""
  61.       s := ""
  62.       while c := reads(f) do {
  63.      if any(okchars,c) then s ||:= c
  64.      else {
  65.         if *s >=  min_string_size then write(header,image(s))
  66.         s := ""
  67.         }
  68.      }
  69.       #
  70.       #  Close this file.
  71.       #
  72.       close(f)
  73.       }
  74. end
  75.